import React, { memo, useCallback } from 'react';
import { Button, message } from 'antd';

import { isSuccess } from '@/utils/request';
import { payoffService } from '@/services/salaryManage/salaryCalculate';

const { doPayoff } = payoffService;

// 执行付款
const PayoffCheck = memo(({ handleItem, year, month, organizationCode, updateStateFn }) => {
    const payoffHandle = useCallback(async () => {
        const payoffRes = await doPayoff({
            year,
            month,
            organizationCode
        })

        if (isSuccess(payoffRes)) {
            message.success(payoffRes.msg)
            updateStateFn()
        } else {
            message.error(payoffRes.msg)
        }
    }, [month, organizationCode, updateStateFn, year]);


    return (
        <Button type="primary" key={handleItem.code} onClick={payoffHandle}>
            {handleItem.name}
        </Button>
    );
});

export default memo(PayoffCheck)
